﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Data;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace HospitalSystem.Core
{
    public class regfamilyLog

    {
        public void radioMariageStatus(RadioButtonList MariageStatus)
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);
            //LiveStatus

            SqlCommand CmdSql2 = new SqlCommand("SELECT MariageStatus FROM [r_MariageStatus]", conn);
            conn.Open();



            DataTable dt = new DataTable();

            SqlDataAdapter sqlDa = new SqlDataAdapter();

            sqlDa.SelectCommand = CmdSql2;
            sqlDa.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                MariageStatus.DataSource = dt;
                MariageStatus.DataTextField = "MariageStatus"; //Where Anwsers is the column name from the database
                MariageStatus.DataValueField = "MariageStatus";
                MariageStatus.DataBind();
            }
            conn.Close();

        }





        public void dropdownMariageStatus(DropDownList MariageStatus)
        {
            
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);
            //LiveStatus

            SqlCommand CmdSql2 = new SqlCommand("SELECT MariageStatus,code FROM [r_MariageStatus]", conn);
            conn.Open();



            SqlDataReader reader4 = CmdSql2.ExecuteReader();

            DataTable dt = new DataTable();
            MariageStatus.Items.Clear();
            ListItem newItem = new ListItem();
            newItem.Text = "เลือกความสัมพันธ์";
            newItem.Value = "0";
            MariageStatus.Items.Add(newItem);

            while (reader4.Read())
            {
                newItem = new ListItem();
                newItem.Text = reader4["MariageStatus"].ToString();
                newItem.Value = reader4["code"].ToString();
                MariageStatus.Items.Add(newItem);
            }


        }







       






        public void radioLiveStatus(RadioButtonList LiveStatus)
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);
            SqlCommand CmdSql22 = new SqlCommand("SELECT LiveStatus FROM [r_LiveStatus]", conn);
            conn.Open();

            DataTable dt2 = new DataTable();

            SqlDataAdapter sqlDa2 = new SqlDataAdapter();

            sqlDa2.SelectCommand = CmdSql22;
            sqlDa2.Fill(dt2);
            if (dt2.Rows.Count > 0)
            {
                LiveStatus.DataSource = dt2;
                LiveStatus.DataTextField = "LiveStatus"; //Where Anwsers is the column name from the database
                LiveStatus.DataValueField = "LiveStatus";
                LiveStatus.DataBind();
            }
            conn.Close();



        }











        // ดึงข้อมูล สถานะขึ้นให้ดู
        public void loaddataMariageStatus(RadioButtonList MariageStatus,Label cid_label)
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT MariageStatus FROM [Family] where CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", cid_label.Text);

            SqlDataReader reader2 = CmdSql2.ExecuteReader();



            if (reader2.Read())
            {

                MariageStatus.Text = reader2["MariageStatus"].ToString();

            }
            else
            {
                //MessageBox("ไม่พบเลขบัตรครับ");
            }
            conn.Close();
            reader2.Close();

        }




        //ddd
        public void loaddataCarer(Label cid_label, TextBox Name, TextBox LastName, TextBox CID, RadioButtonList LiveStatus, TextBox Race, TextBox Religion, Label fcid, TextBox LiveHouseNumber, TextBox LiveHouseName, TextBox LiveHouseMoo, TextBox LiveHousesoy, TextBox LiveStreetName, TextBox Livetambon, TextBox LiveCity, TextBox LiveProvince, TextBox LivePostcode, TextBox CensusHouseNumber, TextBox CensusHouseName, TextBox CensusHouseMoo, TextBox CensusHousesoy, TextBox CensusStreetName, TextBox Censustambon, TextBox CensusCity, TextBox CensusProvince, TextBox CensusPostcode, TextBox IncomePerMonth, TextBox AddressOccupation, TextBox OherIncome, TextBox OherIncomeFrom, RadioButtonList EduLevel, RadioButtonList Occupation, DropDownList MariageStatus, TextBox LastNation)
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT Name,LastName,fCID,LiveStatus,Nation,Race,Religion,LiveHouseNumber,LiveHouseName,LiveHouseMoo,LiveHousesoy,LiveStreetName,Livetambon,LiveCity,LiveProvince,LivePostcode,CensusHouseNumber,CensusHouseName,CensusHouseMoo,CensusHousesoy,CensusStreetName,Censustambon,CensusCity,CensusProvince,CensusPostcode,IncomePerMonth,EduLevel,AddressOccupation,Occupation,OherIncome,OherIncomeFrom,MariageStatus FROM [Carer] where CID=@CID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", cid_label.Text);
      
            SqlDataReader reader2 = CmdSql2.ExecuteReader();



            if (reader2.Read())
            {
                Name.Text = reader2["Name"].ToString();
                LastName.Text = reader2["LastName"].ToString();
                CID.Text = reader2["fCID"].ToString();
                LiveStatus.Text = reader2["LiveStatus"].ToString();
                Race.Text = reader2["Race"].ToString();
                Religion.Text = reader2["Religion"].ToString();
                LiveHouseNumber.Text = reader2["LiveHouseNumber"].ToString();
                LiveHouseName.Text = reader2["LiveHouseName"].ToString();
                LiveHouseMoo.Text = reader2["LiveHouseMoo"].ToString();
                LiveHousesoy.Text = reader2["LiveHousesoy"].ToString();
                Livetambon.Text = reader2["Livetambon"].ToString();
                LiveCity.Text = reader2["LiveCity"].ToString();
                LiveProvince.Text = reader2["LiveProvince"].ToString();
                LivePostcode.Text = reader2["LivePostcode"].ToString();
                CensusHouseNumber.Text = reader2["CensusHouseNumber"].ToString();
                CensusHouseName.Text = reader2["CensusHouseName"].ToString();
                CensusHouseMoo.Text = reader2["CensusHouseMoo"].ToString();
                CensusHousesoy.Text = reader2["CensusHousesoy"].ToString();
                Censustambon.Text = reader2["Censustambon"].ToString();
                CensusCity.Text = reader2["CensusCity"].ToString();
                CensusProvince.Text = reader2["CensusProvince"].ToString();
                CensusPostcode.Text = reader2["CensusPostcode"].ToString();
                IncomePerMonth.Text = reader2["IncomePerMonth"].ToString();
                OherIncome.Text = reader2["OherIncome"].ToString();
                OherIncomeFrom.Text = reader2["OherIncomeFrom"].ToString();
                EduLevel.SelectedValue = reader2["EduLevel"].ToString();
                Occupation.SelectedValue = reader2["Occupation"].ToString();
                MariageStatus.SelectedValue = reader2["MariageStatus"].ToString();
                AddressOccupation.Text = reader2["AddressOccupation"].ToString();
                LastNation.Text = reader2["Nation"].ToString();
                CensusStreetName.Text = reader2["CensusStreetName"].ToString();
                LiveStreetName.Text = reader2["LiveStreetName"].ToString();
            }
            else
            {

            }
            conn.Close();
            reader2.Close();
        }







        public void loaddatafamily(Label cid_label, TextBox Name, TextBox LastName, TextBox CID, RadioButtonList LiveStatus, TextBox Race, TextBox Religion, Label fcid, TextBox LiveHouseNumber, TextBox LiveHouseName, TextBox LiveHouseMoo, TextBox LiveHousesoy, TextBox LiveStreetName, TextBox Livetambon, TextBox LiveCity, TextBox LiveProvince, TextBox LivePostcode, TextBox CensusHouseNumber, TextBox CensusHouseName, TextBox CensusHouseMoo, TextBox CensusHousesoy, TextBox CensusStreetName, TextBox Censustambon, TextBox CensusCity, TextBox CensusProvince, TextBox CensusPostcode, TextBox IncomePerMonth, TextBox AddressOccupation, TextBox OherIncome, TextBox OherIncomeFrom, RadioButtonList EduLevel, RadioButtonList Occupation, DropDownList MariageStatus, TextBox LastNation)
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);

            SqlCommand CmdSql2 = new SqlCommand("SELECT Name,LastName,fCID,LiveStatus,Nation,Race,Religion,LiveHouseNumber,LiveHouseName,LiveHouseMoo,LiveHousesoy,LiveStreetName,Livetambon,LiveCity,LiveProvince,LivePostcode,CensusHouseNumber,CensusHouseName,CensusHouseMoo,CensusHousesoy,CensusStreetName,Censustambon,CensusCity,CensusProvince,CensusPostcode,IncomePerMonth,EduLevel,AddressOccupation,Occupation,OherIncome,OherIncomeFrom,MariageStatus FROM [Family] where CID=@CID and fCID=@fCID", conn);
            conn.Open();
            CmdSql2.Parameters.AddWithValue("@CID", cid_label.Text);
            CmdSql2.Parameters.AddWithValue("@fCID", fcid.Text);
            SqlDataReader reader2 = CmdSql2.ExecuteReader();



            if (reader2.Read())
            {
                Name.Text = reader2["Name"].ToString();
                LastName.Text = reader2["LastName"].ToString();
                CID.Text = reader2["fCID"].ToString();
                LiveStatus.Text = reader2["LiveStatus"].ToString();
                Race.Text = reader2["Race"].ToString();
                Religion.Text = reader2["Religion"].ToString();
                LiveHouseNumber.Text = reader2["LiveHouseNumber"].ToString();
                LiveHouseName.Text = reader2["LiveHouseName"].ToString();
                LiveHouseMoo.Text = reader2["LiveHouseMoo"].ToString();
                LiveHousesoy.Text = reader2["LiveHousesoy"].ToString();
                Livetambon.Text = reader2["Livetambon"].ToString();
                LiveCity.Text = reader2["LiveCity"].ToString();
                LiveProvince.Text = reader2["LiveProvince"].ToString();
                LivePostcode.Text = reader2["LivePostcode"].ToString();
                CensusHouseNumber.Text = reader2["CensusHouseNumber"].ToString();
                CensusHouseName.Text = reader2["CensusHouseName"].ToString();
                CensusHouseMoo.Text = reader2["CensusHouseMoo"].ToString();
                CensusHousesoy.Text = reader2["CensusHousesoy"].ToString();
                Censustambon.Text = reader2["Censustambon"].ToString();
                CensusCity.Text = reader2["CensusCity"].ToString();
                CensusProvince.Text = reader2["CensusProvince"].ToString();
                CensusPostcode.Text = reader2["CensusPostcode"].ToString();
                IncomePerMonth.Text = reader2["IncomePerMonth"].ToString();
                OherIncome.Text = reader2["OherIncome"].ToString();
                OherIncomeFrom.Text = reader2["OherIncomeFrom"].ToString();
                EduLevel.SelectedValue = reader2["EduLevel"].ToString();
                Occupation.SelectedValue = reader2["Occupation"].ToString();
                MariageStatus.SelectedValue = reader2["MariageStatus"].ToString();
                AddressOccupation.Text = reader2["AddressOccupation"].ToString();
                LastNation.Text = reader2["Nation"].ToString();
                CensusStreetName.Text = reader2["CensusStreetName"].ToString();
                LiveStreetName.Text = reader2["LiveStreetName"].ToString();
            }
            else
            {

            }
            conn.Close();
            reader2.Close();

        }






        public void insertregdata(Label cid_label, RadioButtonList MariageStatus, String Name, String LastName, String CID, String Race, String Religion, RadioButtonList LiveStatus, String LiveHouseNumber, String LiveHouseName, String LiveHouseMoo, String LiveHousesoy, String LiveStreetName, String Livetambon, String LiveCity, String LiveProvince, String LivePostcode, String CensusHouseNumber, String CensusHouseName, String CensusHouseMoo, String CensusHousesoy, String CensusStreetName, String Censustambon, String CensusCity, String CensusProvince, String CensusPostcode, String IncomePerMonth, RadioButtonList EduLevel, String AddressOccupation, RadioButtonList Occupation, String OherIncome, String OherIncomeFrom, String LastNation)
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection conn2 = new SqlConnection(constr);
            SqlCommand CmdSql2 = new SqlCommand("INSERT INTO [Family] (CID,MariageStatus,Name,LastName,fCID,Race,Religion,LiveStatus,LiveHouseNumber,LiveHouseName,LiveHouseMoo,LiveHousesoy,LiveStreetName,Livetambon,LiveCity,LiveProvince,LivePostcode,CensusHouseNumber,CensusHouseName,CensusHouseMoo,CensusHousesoy,CensusStreetName,Censustambon,CensusCity,CensusProvince,CensusPostcode,IncomePerMonth,EduLevel,AddressOccupation,Occupation,OherIncome,OherIncomeFrom) VALUES (@CID,@MariageStatus,@Name,@LastName,@fCID,@Race,@Religion,@LiveStatus,@LiveHouseNumber,@LiveHouseName,@LiveHouseMoo,@LiveHousesoy,@LiveStreetName,@Livetambon,@LiveCity,@LiveProvince,@LivePostcode,@CensusHouseNumber,@CensusHouseName,@CensusHouseMoo,@CensusHousesoy,@CensusStreetName,@Censustambon,@CensusCity,@CensusProvince,@CensusPostcode,@IncomePerMonth,@EduLevel,@AddressOccupation,@Occupation,@OherIncome,@OherIncomeFrom)", conn2);
            conn2.Open();
            CmdSql2.Parameters.AddWithValue("@CID", cid_label.Text);
            

            CmdSql2.Parameters.AddWithValue("@MariageStatus", MariageStatus.SelectedValue);
            CmdSql2.Parameters.AddWithValue("@Name", Name);
            CmdSql2.Parameters.AddWithValue("@LastName", LastName);
            CmdSql2.Parameters.AddWithValue("@fCID", CID);
            CmdSql2.Parameters.AddWithValue("@Nation", LastNation);
            CmdSql2.Parameters.AddWithValue("@Race", Race);
            CmdSql2.Parameters.AddWithValue("@Religion", Religion);
            CmdSql2.Parameters.AddWithValue("@LiveStatus", LiveStatus.SelectedValue);
            CmdSql2.Parameters.AddWithValue("@LiveHouseNumber", LiveHouseNumber);
            CmdSql2.Parameters.AddWithValue("@LiveHouseName", LiveHouseName);
            CmdSql2.Parameters.AddWithValue("@LiveHouseMoo", LiveHouseMoo);
            CmdSql2.Parameters.AddWithValue("@LiveHousesoy", LiveHousesoy);
            CmdSql2.Parameters.AddWithValue("@LiveStreetName",LiveStreetName);
            CmdSql2.Parameters.AddWithValue("@Livetambon", Livetambon);
            CmdSql2.Parameters.AddWithValue("@LiveCity",LiveCity);
            CmdSql2.Parameters.AddWithValue("@LiveProvince",LiveProvince);
            CmdSql2.Parameters.AddWithValue("@LivePostcode", LivePostcode);
            CmdSql2.Parameters.AddWithValue("@CensusHouseNumber", CensusHouseNumber);
            CmdSql2.Parameters.AddWithValue("@CensusHouseName",CensusHouseName);
            CmdSql2.Parameters.AddWithValue("@CensusHouseMoo", CensusHouseMoo);
            CmdSql2.Parameters.AddWithValue("@CensusHousesoy", CensusHousesoy);
            CmdSql2.Parameters.AddWithValue("@CensusStreetName", CensusStreetName);
            CmdSql2.Parameters.AddWithValue("@Censustambon", Censustambon);
            CmdSql2.Parameters.AddWithValue("@CensusCity", CensusCity);
            CmdSql2.Parameters.AddWithValue("@CensusProvince", CensusProvince);
            CmdSql2.Parameters.AddWithValue("@CensusPostcode", CensusPostcode);
            CmdSql2.Parameters.AddWithValue("@IncomePerMonth" , IncomePerMonth);
            CmdSql2.Parameters.AddWithValue("@EduLevel",EduLevel.SelectedValue);
            CmdSql2.Parameters.AddWithValue("@AddressOccupation", AddressOccupation);
            CmdSql2.Parameters.AddWithValue("@Occupation", Occupation.SelectedValue);
            CmdSql2.Parameters.AddWithValue("@OherIncome", OherIncome);
            CmdSql2.Parameters.AddWithValue("@OherIncomeFrom" ,OherIncomeFrom);
            CmdSql2.ExecuteNonQuery();
            conn2.Close();

        }









        public void showlistfamily2(Label cid_label,GridView familylist)
        {

            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection scon = new SqlConnection(constr);
            SqlCommand cmd = new SqlCommand("select a.Name as Name,a.LastName as LastName,a.fCID as fCID,b.MariageStatus as MariageStatus,a.CID as CID from Family a join r_MariageStatus b on a.MariageStatus=b.code where CID=@CID", scon);
            cmd.Parameters.AddWithValue("@CID", cid_label.Text);
            scon.Open();
            //SqlDataReader reader = cmd.ExecuteReader();

            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            familylist.DataSource = ds;
            familylist.DataBind();
            scon.Close();

                //familylist.DataSource = reader;
                //familylist.DataBind();
                

            


           //reader.Close();
         
        }





        public void showlistCarer(Label cid_label, GridView Carerlist)
        {

            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection scon = new SqlConnection(constr);
            SqlCommand cmd = new SqlCommand("select a.Name as Name,a.LastName as LastName,a.fCID as fCID,b.MariageStatus as MariageStatus,a.CID as CID from Carer a join r_MariageStatus b on a.MariageStatus=b.code where CID=@CID", scon);
            cmd.Parameters.AddWithValue("@CID", cid_label.Text);
            scon.Open();
            SqlDataReader reader = cmd.ExecuteReader();



            Carerlist.DataSource = reader;
            Carerlist.DataBind();





            reader.Close();

        }







        public void insertregdataCarer(Label cid_label, String Name, String LastName, String CID, String Race, String Religion, RadioButtonList LiveStatus, String LiveHouseNumber, String LiveHouseName, String LiveHouseMoo, String LiveHousesoy, String LiveStreetName, String Livetambon, String LiveCity, String LiveProvince, String LivePostcode, String CensusHouseNumber, String CensusHouseName, String CensusHouseMoo, String CensusHousesoy, String CensusStreetName, String Censustambon, String CensusCity, String CensusProvince, String CensusPostcode, String IncomePerMonth, RadioButtonList EduLevel, String AddressOccupation, RadioButtonList Occupation, String OherIncome, String OherIncomeFrom, Label fcid, DropDownList MariageStatus, String LastNation)
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;

                                    


            SqlConnection conn2 = new SqlConnection(constr);
            SqlCommand CmdSql = new SqlCommand("delete from [Carer] where CID=@CID", conn2);
            conn2.Open();
            CmdSql.Parameters.AddWithValue("@CID", cid_label.Text);

            CmdSql.ExecuteNonQuery();
            conn2.Close();


            
            
            SqlCommand CmdSql2 = new SqlCommand("INSERT INTO [Carer] (CID,Name,LastName,fCID,Race,Religion,LiveStatus,LiveHouseNumber,LiveHouseName,LiveHouseMoo,LiveHousesoy,LiveStreetName,Livetambon,LiveCity,LiveProvince,LivePostcode,CensusHouseNumber,CensusHouseName,CensusHouseMoo,CensusHousesoy,CensusStreetName,Censustambon,CensusCity,CensusProvince,CensusPostcode,IncomePerMonth,EduLevel,AddressOccupation,Occupation,OherIncome,OherIncomeFrom,MariageStatus,Nation) VALUES (@CID,@Name,@LastName,@fCID,@Race,@Religion,@LiveStatus,@LiveHouseNumber,@LiveHouseName,@LiveHouseMoo,@LiveHousesoy,@LiveStreetName,@Livetambon,@LiveCity,@LiveProvince,@LivePostcode,@CensusHouseNumber,@CensusHouseName,@CensusHouseMoo,@CensusHousesoy,@CensusStreetName,@Censustambon,@CensusCity,@CensusProvince,@CensusPostcode,@IncomePerMonth,@EduLevel,@AddressOccupation,@Occupation,@OherIncome,@OherIncomeFrom,@MariageStatus,@Nation)", conn2);
            conn2.Open();
            CmdSql2.Parameters.AddWithValue("@CID", cid_label.Text);


            CmdSql2.Parameters.AddWithValue("@Name", Name);
            CmdSql2.Parameters.AddWithValue("@LastName", LastName);
            CmdSql2.Parameters.AddWithValue("@fCID", CID);
            CmdSql2.Parameters.AddWithValue("@Nation", LastNation);
            CmdSql2.Parameters.AddWithValue("@Race", Race);
            CmdSql2.Parameters.AddWithValue("@Religion", Religion);

            CmdSql2.Parameters.AddWithValue("@MariageStatus", MariageStatus.SelectedValue);
            CmdSql2.Parameters.AddWithValue("@LiveStatus", LiveStatus.SelectedValue);
            CmdSql2.Parameters.AddWithValue("@LiveHouseNumber", LiveHouseNumber);
            CmdSql2.Parameters.AddWithValue("@LiveHouseName", LiveHouseName);
            CmdSql2.Parameters.AddWithValue("@LiveHouseMoo", LiveHouseMoo);
            CmdSql2.Parameters.AddWithValue("@LiveHousesoy", LiveHousesoy);
            CmdSql2.Parameters.AddWithValue("@LiveStreetName", LiveStreetName);
            CmdSql2.Parameters.AddWithValue("@Livetambon", Livetambon);
            CmdSql2.Parameters.AddWithValue("@LiveCity", LiveCity);
            CmdSql2.Parameters.AddWithValue("@LiveProvince", LiveProvince);
            CmdSql2.Parameters.AddWithValue("@LivePostcode", LivePostcode);
            CmdSql2.Parameters.AddWithValue("@CensusHouseNumber", CensusHouseNumber);
            CmdSql2.Parameters.AddWithValue("@CensusHouseName", CensusHouseName);
            CmdSql2.Parameters.AddWithValue("@CensusHouseMoo", CensusHouseMoo);
            CmdSql2.Parameters.AddWithValue("@CensusHousesoy", CensusHousesoy);
            CmdSql2.Parameters.AddWithValue("@CensusStreetName", CensusStreetName);
            CmdSql2.Parameters.AddWithValue("@Censustambon", Censustambon);
            CmdSql2.Parameters.AddWithValue("@CensusCity", CensusCity);
            CmdSql2.Parameters.AddWithValue("@CensusProvince", CensusProvince);
            CmdSql2.Parameters.AddWithValue("@CensusPostcode", CensusPostcode);
            CmdSql2.Parameters.AddWithValue("@IncomePerMonth", IncomePerMonth);
            CmdSql2.Parameters.AddWithValue("@EduLevel", EduLevel.SelectedValue);
            CmdSql2.Parameters.AddWithValue("@AddressOccupation", AddressOccupation);
            CmdSql2.Parameters.AddWithValue("@Occupation", Occupation.SelectedValue);
            CmdSql2.Parameters.AddWithValue("@OherIncome", OherIncome);
            CmdSql2.Parameters.AddWithValue("@OherIncomeFrom", OherIncomeFrom);
            CmdSql2.ExecuteNonQuery();
            conn2.Close();

        }










       



        //regfamilyedit



        public void insertregdataFamily(Label cid_label, String Name, String LastName, String CID, String Race, String Religion, RadioButtonList LiveStatus, String LiveHouseNumber, String LiveHouseName, String LiveHouseMoo, String LiveHousesoy, String LiveStreetName, String Livetambon, String LiveCity, String LiveProvince, String LivePostcode, String CensusHouseNumber, String CensusHouseName, String CensusHouseMoo, String CensusHousesoy, String CensusStreetName, String Censustambon, String CensusCity, String CensusProvince, String CensusPostcode, String IncomePerMonth, RadioButtonList EduLevel, String AddressOccupation, RadioButtonList Occupation, String OherIncome, String OherIncomeFrom, Label fcid, DropDownList MariageStatus, String LastNation)
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;




            SqlConnection conn2 = new SqlConnection(constr);
            SqlCommand CmdSql = new SqlCommand("delete from [Family] where CID=@CID and fCID=@fCID", conn2);
            conn2.Open();
            CmdSql.Parameters.AddWithValue("@CID", cid_label.Text);
            CmdSql.Parameters.AddWithValue("@fCID", fcid.Text);
            CmdSql.ExecuteNonQuery();
            conn2.Close();





            SqlCommand CmdSql2 = new SqlCommand("INSERT INTO [Family] (CID,Name,LastName,fCID,Race,Religion,LiveStatus,LiveHouseNumber,LiveHouseName,LiveHouseMoo,LiveHousesoy,LiveStreetName,Livetambon,LiveCity,LiveProvince,LivePostcode,CensusHouseNumber,CensusHouseName,CensusHouseMoo,CensusHousesoy,CensusStreetName,Censustambon,CensusCity,CensusProvince,CensusPostcode,IncomePerMonth,EduLevel,AddressOccupation,Occupation,OherIncome,OherIncomeFrom,MariageStatus,Nation) VALUES (@CID,@Name,@LastName,@fCID,@Race,@Religion,@LiveStatus,@LiveHouseNumber,@LiveHouseName,@LiveHouseMoo,@LiveHousesoy,@LiveStreetName,@Livetambon,@LiveCity,@LiveProvince,@LivePostcode,@CensusHouseNumber,@CensusHouseName,@CensusHouseMoo,@CensusHousesoy,@CensusStreetName,@Censustambon,@CensusCity,@CensusProvince,@CensusPostcode,@IncomePerMonth,@EduLevel,@AddressOccupation,@Occupation,@OherIncome,@OherIncomeFrom,@MariageStatus,@Nation)", conn2);
            conn2.Open();
            CmdSql2.Parameters.AddWithValue("@CID", cid_label.Text);


            CmdSql2.Parameters.AddWithValue("@Name", Name);
            CmdSql2.Parameters.AddWithValue("@LastName", LastName);
            CmdSql2.Parameters.AddWithValue("@fCID", CID);
            CmdSql2.Parameters.AddWithValue("@Nation", LastNation);
            CmdSql2.Parameters.AddWithValue("@Race", Race);
            CmdSql2.Parameters.AddWithValue("@Religion", Religion);

            CmdSql2.Parameters.AddWithValue("@MariageStatus", MariageStatus.SelectedValue);
            CmdSql2.Parameters.AddWithValue("@LiveStatus", LiveStatus.SelectedValue);
            CmdSql2.Parameters.AddWithValue("@LiveHouseNumber", LiveHouseNumber);
            CmdSql2.Parameters.AddWithValue("@LiveHouseName", LiveHouseName);
            CmdSql2.Parameters.AddWithValue("@LiveHouseMoo", LiveHouseMoo);
            CmdSql2.Parameters.AddWithValue("@LiveHousesoy", LiveHousesoy);
            CmdSql2.Parameters.AddWithValue("@LiveStreetName", LiveStreetName);
            CmdSql2.Parameters.AddWithValue("@Livetambon", Livetambon);
            CmdSql2.Parameters.AddWithValue("@LiveCity", LiveCity);
            CmdSql2.Parameters.AddWithValue("@LiveProvince", LiveProvince);
            CmdSql2.Parameters.AddWithValue("@LivePostcode", LivePostcode);
            CmdSql2.Parameters.AddWithValue("@CensusHouseNumber", CensusHouseNumber);
            CmdSql2.Parameters.AddWithValue("@CensusHouseName", CensusHouseName);
            CmdSql2.Parameters.AddWithValue("@CensusHouseMoo", CensusHouseMoo);
            CmdSql2.Parameters.AddWithValue("@CensusHousesoy", CensusHousesoy);
            CmdSql2.Parameters.AddWithValue("@CensusStreetName", CensusStreetName);
            CmdSql2.Parameters.AddWithValue("@Censustambon", Censustambon);
            CmdSql2.Parameters.AddWithValue("@CensusCity", CensusCity);
            CmdSql2.Parameters.AddWithValue("@CensusProvince", CensusProvince);
            CmdSql2.Parameters.AddWithValue("@CensusPostcode", CensusPostcode);
            CmdSql2.Parameters.AddWithValue("@IncomePerMonth", IncomePerMonth);
            CmdSql2.Parameters.AddWithValue("@EduLevel", EduLevel.SelectedValue);
            CmdSql2.Parameters.AddWithValue("@AddressOccupation", AddressOccupation);
            CmdSql2.Parameters.AddWithValue("@Occupation", Occupation.SelectedValue);
            CmdSql2.Parameters.AddWithValue("@OherIncome", OherIncome);
            CmdSql2.Parameters.AddWithValue("@OherIncomeFrom", OherIncomeFrom);
            CmdSql2.ExecuteNonQuery();
            conn2.Close();

        }









        public void detetecarer(Label cid_label)
        {
            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;




            SqlConnection conn2 = new SqlConnection(constr);
            SqlCommand CmdSql = new SqlCommand("delete from [Carer] where CID=@CID", conn2);
            conn2.Open();
            CmdSql.Parameters.AddWithValue("@CID", cid_label.Text);
          
            CmdSql.ExecuteNonQuery();
            conn2.Close();




        }






    }
}